package 校赛.真题;

import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec 校赛.真题
 * @since 2023 - 03 - 27 - 14:57
 */
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] targets = new int[n];
        for(int i = 0; i < n; i++){
            targets[i] = sc.nextInt();
        }
        int[][] choices = new int[n][2];
        for(int i = 0; i < n; i++){
            choices[i][0] = sc.nextInt();
            choices[i][1] = sc.nextInt();
        }
        int res = 0;
        //二进制枚举
        int cnt;
        for(int i = 0; i < (1 << n); i++){
            //1表示提升到困难
            cnt = 0;
            for(int j = 0; j < n; j++){
                if(((i >> j) & 1) == 1) cnt++;
            }
            //合法情况
            if(cnt <= m){
                PriorityQueue<Integer> queue = new PriorityQueue<>((e1, e2) -> e2 - e1);
                for(int j = 0; j < n; j++){
                    if(((i >> j) & 1) == 1) {
                        queue.offer(choices[j][1]);
                    }else{
                        queue.offer(choices[j][0]);
                    }
                }
                int score = 0, winCnt = 0, cur = 0;
                while(!queue.isEmpty()){
                    score += queue.poll();
                    if(score >= targets[cur]) winCnt++;
                    cur++;
                }
                res = Math.max(res, winCnt);
            }
        }
        System.out.println(res);
    }
}
